#coding=gb2312
#-------------------------------------------------------------------------------
# Name:        ??1
# Purpose:
#
# Author:      weigun
#
# Created:     11-08-2011
# Copyright:   (c) weigun 2011
# Licence:     <your licence>
#-------------------------------------------------------------------------------
#!/usr/bin/env python
import sqlite3
class DbHandler():
    def __init__(self,text_factory = False):
        datafile = r"item.datafile"
        self.conn = sqlite3.connect(datafile)
        if text_factory:
            self.conn.text_factory = str

    def connect(self,db_name):
        self.conn = sqlite3.connect(db_name)


    def exec_sql(self,sql):
        if not sql == '' : self.conn.execute(sql)

    def query(self,sql):
        if not sql == '':
            cur = self.conn.cursor()
            cur.execute(sql)
            return cur.fetchall()

    def write_db(self,sql,*values):
        self.conn.execute(sql,values)

    def commit(self):
        self.conn.commit()




